package com.chanyachting.emall.action.recruitmentinformation;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.chanyachting.emall.domain.Joblist;
import com.chanyachting.emall.domain.Recruitmentinformation;
import com.chanyachting.emall.form.RecruitmentinformationForm;
import com.chanyachting.emall.service.RecruitmentinformationService;
import com.chanyachting.emall.serviceImpl.RecruitmentinformationServiceImpl;
import com.chanyachting.emall.util.DateUtil;
import com.chanyachting.emall.util.RequestUtil;

public class CreateAction extends Action {

	
	//创建招聘信息
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		RequestUtil ru=new RequestUtil(request);
		
		RecruitmentinformationForm riform=(RecruitmentinformationForm)form;
		
		Recruitmentinformation ri=new Recruitmentinformation();
		
		BeanUtils.copyProperties(ri, riform);
		
		
		ri.setCreateDate(DateUtil.getDate());
		
		ri.setStatus("00");
		
		//从session中获得岗位列表 
		List jobList=(List)ru.getSessionObject(RecruitmentinformationService.JOBLLIST_IN_SESSION, new ArrayList());
		
		for(int i=0;i<jobList.size();i++){
			
			Joblist job=(Joblist)jobList.get(i);
			
			job.setRecruitmentInformation(ri);
			
			ri.addToJoblistSet(job);
		}
		
		RecruitmentinformationService ris=new RecruitmentinformationServiceImpl();
		
		boolean temp=ris.createRecruitmentinformation(ri);
		
		if(temp){
		//创建成功，删除session中的岗位信息
		ru.removeSessionObject(RecruitmentinformationService.JOBLLIST_IN_SESSION);
		}
		
		
		return mapping.findForward("");
	}
	
	
	
	

}
